package com.ruoyi.web.controller.manger;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manger.domain.ResourceDocument;
import com.ruoyi.manger.service.IResourceDocumentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公共资源文档下载Controller
 * 
 * @author ssh
 * @date 2024-12-15
 */
@RestController
@RequestMapping("/manger/document")
public class ResourceDocumentController extends BaseController
{
    @Autowired
    private IResourceDocumentService resourceDocumentService;

    /**
     * 查询公共资源文档下载列表
     */
    @PreAuthorize("@ss.hasPermi('manger:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResourceDocument resourceDocument)
    {
        startPage();
        List<ResourceDocument> list = resourceDocumentService.selectResourceDocumentList(resourceDocument);
        return getDataTable(list);
    }

    /**
     * 导出公共资源文档下载列表
     */
    @PreAuthorize("@ss.hasPermi('manger:document:export')")
    @Log(title = "公共资源文档下载", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResourceDocument resourceDocument)
    {
        List<ResourceDocument> list = resourceDocumentService.selectResourceDocumentList(resourceDocument);
        ExcelUtil<ResourceDocument> util = new ExcelUtil<ResourceDocument>(ResourceDocument.class);
        util.exportExcel(response, list, "公共资源文档下载数据");
    }

    /**
     * 获取公共资源文档下载详细信息
     */
    @PreAuthorize("@ss.hasPermi('manger:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(resourceDocumentService.selectResourceDocumentById(id));
    }

    /**
     * 新增公共资源文档下载
     */
    @PreAuthorize("@ss.hasPermi('manger:document:add')")
    @Log(title = "公共资源文档下载", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResourceDocument resourceDocument)
    {
        return toAjax(resourceDocumentService.insertResourceDocument(resourceDocument));
    }

    /**
     * 修改公共资源文档下载
     */
    @PreAuthorize("@ss.hasPermi('manger:document:edit')")
    @Log(title = "公共资源文档下载", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResourceDocument resourceDocument)
    {
        return toAjax(resourceDocumentService.updateResourceDocument(resourceDocument));
    }

    /**
     * 删除公共资源文档下载
     */
    @PreAuthorize("@ss.hasPermi('manger:document:remove')")
    @Log(title = "公共资源文档下载", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resourceDocumentService.deleteResourceDocumentByIds(ids));
    }
}
